package com.alan.derbydemo.config;

import org.apache.commons.dbcp2.BasicDataSource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * @author alan
 * @description:
 * @date 2021/4/28
 */

/**
 * DataSource配置类
 */
@Configuration
@ConfigurationProperties(prefix = "datasource")
public class DerbyDataSourceConfig {
    private String driver;
    private String url;

    public String getDriver() {
        return driver;
    }

    public void setDriver(String driver) {
        this.driver = driver;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    @Bean
    public DataSource dataSource()
    {
        BasicDataSource bean = new BasicDataSource();

        bean.setDriverClassName(driver);
        bean.setUrl(url);

        return bean;
    }
}
